﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;


namespace MindFactorial.Library
{
    public class XamlConfigSectionHandler : System.Configuration.IConfigurationSectionHandler
    {
        object _xaml_instance = null;

        public T GetInstance<T>()
        {
            return (T)_xaml_instance;
        }

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            StringReader xaml = new StringReader(section.OuterXml);
            XmlReader xaml_reader = XmlReader.Create(xaml);
            _xaml_instance = System.Windows.Markup.XamlReader.Load(xaml_reader);
            return this;
        }

        public static XamlConfigSectionHandler FromConfigSection(string config_section)
        {
            XamlConfigSectionHandler xaml_config_section = (XamlConfigSectionHandler)System.Configuration.ConfigurationManager.GetSection(config_section);
            return xaml_config_section; 
        }

    }
}
